<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>客户状态管理</title>
	<meta name="decorator" content="default"/>
    <link rel="stylesheet" href="${ctxStatic}/bootstrap-table/bootstrap-table.css">
    <script src="${ctxStatic}/bootstrap-table/bootstrap-table.js"></script>
    <script src="${ctxStatic}/bootstrap-table/locale/bootstrap-table-zh-CN.js"></script>
    <script src="${ctxStatic}/bootstrap-table/config.js"></script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/sys/customerStatus/">客户状态列表</a></li>
		<li class="active"><a href="${ctx}/sys/customerStatus/form?id=${customerStatus.id}">客户状态<shiro:hasPermission name="sys:customerStatus:edit">${not empty customerStatus.id?'修改':'添加'}</shiro:hasPermission><shiro:lacksPermission name="sys:customerStatus:edit">查看</shiro:lacksPermission></a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="customerStatus" action="${ctx}/sys/customerStatus/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<form:hidden path="historyFlag"/>
		<sys:message content="${message}"/>
		<div class="control-group">
			<label class="control-label">客户状态：</label>
			<div class="controls">
				<form:input path="content" htmlEscape="false" rows="4" maxlength="255" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
        <div class="control-group">
            <label class="control-label">操作类型：</label>
            <div class="controls">
                <form:radiobuttons path="operations" items="${operationList}"/>
            </div>
        </div>
        <c:if test="${not empty customerStatus.id}">
		<div class="control-group">
			<label class="control-label">创建时间：</label>
            <fmt:formatDate value="${customerStatus.dateCreated}" pattern="yyyy-MM-dd HH:mm:ss"/>
		</div>
		<div class="control-group">
			<label class="control-label">更新时间：</label>
			<div class="controls">
                <fmt:formatDate value="${customerStatus.dateCreated}" pattern="yyyy-MM-dd HH:mm:ss"/>
			</div>
		</div>
        <div class="control-group">
            <table id="contentTable" data-url="${ctx}/sys/customerStatus/listDetailAjaxData">
                <thead>
                <tr>
                    <th data-field="state" data-align="center" data-formatter="indexFormatter">
                        <shiro:hasPermission name="sys:customerStatus:edit">
                            <i id="addBtn" class="icon icon-plus" style="cursor: pointer;" title="添加详情"></i>
                            <div id="saveDlg" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="saveDetailLabel" aria-hidden="true">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                                    <h5 id="saveDetailLabel" style="text-align: left">增加明细</h5>
                                </div>
                                <div class="modal-body">
                                    <div class="control-group">
                                        <label class="control-label">详细信息：</label>
                                        <div class="controls">
                                            <input type="hidden" id="detailId"/>
                                            <input type="hidden" id="customerStatusId" value="${customerStatus.id}"/>
                                            <input id="causeDesc" size="512" maxlength="512" class="input-xlarge required"/>
                                            <span class="help-inline"><font color="red">*</font></span>
                                        </div>
                                    </div>
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-small" data-dismiss="modal" aria-hidden="true">关闭</button>
                                    <button id="saveDetail" type="button" class="btn btn-small btn-primary">保存</button>
                                </div>
                            </div>
                        </shiro:hasPermission>
                    </th>
                    <th data-field="causeDesc"  data-align="left">内容</th>
                    <th data-field="dateCreated"  data-align="center">创建时间</th>
                    <th data-field="lastUpdated"  data-align="center">更新时间</th>
                    <th data-field="operate" data-align="center" data-formatter="operateFormatter" data-events="operateEvents" >操作</th>
                </tr>
                </thead>
            </table>
        </div>
        </c:if>
		<div class="form-actions">
			<shiro:hasPermission name="sys:customerStatus:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;</shiro:hasPermission>
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1*${customerStatus.historyFlag})"/>
		</div>
	</form:form>
    <script type="text/javascript">
        $(document).ready(function() {
            $("#inputForm").validate({
                 submitHandler: function(form){
                     loading('正在提交，请稍等...');
                     form.submit();
                 },
                 errorContainer: "#messageBox",
                 errorPlacement: function(error, element) {
                     $("#messageBox").text("输入有误，请先更正。");
                     if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
                         error.appendTo(element.parent().parent());
                     } else {
                         error.insertAfter(element);
                     }
                 }
             });
            $("#contentTable").bootstrapTable(
                $.fn.BTConfigSimple({
                    pageList: [5, 50, 100],
                    pageSize: 5,
                    sortName: "lastUpdated",
                    queryParams: function (params) {
                        params.pageNo = params.pageNumber;
                        if(params.sortName){
                            params.sortName = params.sortName.replace(/[A-Z]/g,function(code){
                                return "_"+code;
                            });
                            params.sortName = params.sortName.toUpperCase();
                            params.orderBy = params.sortName + " " + params.sortOrder;
                        }
                        params.customerStatusId = '${customerStatus.id}';
                        return params;
                    }
                })
            );
            $("#addBtn").click(function(){
                $("#saveDetailLabel").text("创建明细");
                $("#detailId").val("");
                $("#causeDesc").val("");
                $("#saveDlg").modal('show');
            });
            $("#saveDetail").click(function(){
                $.ajax({
                   url: "${ctx}/sys/customerStatus/detailSave",
                   type: "post",
                   data: {
                       id:$("#detailId").val(),
                       customerStatusId:$("#customerStatusId").val(),
                       causeDesc:$("#causeDesc").val()
                   },
                   dataType: "json",
                   success: function (data) {
                       if (data.state == true) {
                           showTip(data.message);
                           refresh();
                           $("#saveDlg").modal('hide');
                       } else {
                           alertx(data.message);
                       }
                   },
                   error: function (data, state, error) {
                       alertx(data.responseText, null, '请求错误');
                   }
               });
            });
        });
        function refresh(){
            $("#contentTable").bootstrapTable('refresh');
        }
        function indexFormatter(value, row, index){
            return index + 1;
        }
        function operateFormatter(value, row, index){
            var array = [];
            array.push('<a class="edit" href="javascript:void(0);" title="编辑/查看">');
            array.push('<i class="icon icon-edit"></i>');
            array.push('</a>');
            <shiro:hasPermission name="sys:customerStatus:edit">
            array.push('  ');
            array.push('<a class="remove" href="javascript:void(0);" title="删除">');
            array.push('<i class="icon icon-remove"></i>');
            array.push('</a>');
            </shiro:hasPermission>
            return array.join('');
        }
        var operateEvents = {
            'click .remove': function (e, value, row, index) {
                confirmx("您确认要删除记录[" + row.causeDesc + "]?",
                 function () {
                     $.ajax({
                        url: "${ctx}/sys/customerStatus/detailDelete",
                        type: "post",
                        data: {id: row.id},
                        dataType: "json",
                        success: function (data) {
                            if (data.state == true) {
                                showTip(data.message);
                                refresh();
                            } else {
                                alertx(data.message);
                            }
                        },
                        error: function (data, state, error) {
                            alertx(data.responseText, null, '请求错误');
                        }
                    });});
            },
            'click .edit':function(e, value, row, index){
                $("#saveDetailLabel").text("修改明细");
                $("#detailId").val(row.id);
                $("#causeDesc").val(row.causeDesc);
                $("#saveDlg").modal('show');
            }
        };
    </script>
</body>
</html>